// 用来保存用户信息的模块
import { login } from '@/api/user'
// 2引入cookies三个函数后 调用
import { getToken, setToken, removeToken } from '@/utils/auth'

const state = {
  token: getToken()
}
const mutations = {
  setToken(state, token) {
    state.token = token
    setToken(token)
  },
  removeToken(state) {
    state.token = ''
    removeToken()
  }
}
const actions = {
  async getToken(store, data) {
    const res = await login(data)
    console.log(14, res)
    store.commit('setToken', res.data.jwt)
  },
  logout(store) {
    // 实现退出功能删除token
    store.commit('removeToken')
  }
}

export default {
  namespaced: true,
  state,
  mutations,
  actions
}
